home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / os2 / elvis172.zip / alias.c next >
C/C++ Source or Header  |  1993-01-06  |  2KB  |  102 lines

  1. /* alias.c */
  2.  
  3. /* Author:
  4.  *        Peter Reinig
  5.  *        Universitaet Kaiserslautern
  6.  *        Postfach 3049
  7.  *        7650 Kaiserslautern
  8.  *        W. Germany
  9.  *        reinig@physik.uni-kl.de
  10.  */
  11.  
  12. /* This tiny program executes elvis with the flags that are appropriate
  13.  * for a given command name.  This program is used only on systems that
  14.  * don't allow UNIX-style file links.
  15.  *
  16.  * The benefit of this program is: instead of having 5 copies of elvis
  17.  * on your disk, you only need one copy of elvis and 4 copies of this
  18.  * little program.
  19.  */
  20.  
  21. #include <stdio.h>
  22. #include "config.h"
  23.  
  24. #if OSK
  25. #define ELVIS    "/dd/usr/cmds/elvis"
  26. #else
  27. #define ELVIS    "elvis"
  28. #endif
  29.  
  30. extern char **environ;
  31. extern int errno;
  32.  
  33. main(argc, argv)
  34.     int    argc;
  35.     char    *argv[];
  36. {
  37.     int    pid, i, j;
  38.     int    letter;
  39.     char    **argblk;
  40. #if OSK
  41.     extern int chainc();
  42. #endif
  43.  
  44.     /* allocate enough space for a copy of the argument list, plus a
  45.      * terminating NULL, plus maybe an added flag.
  46.      */
  47.     argblk = (char **) malloc((argc + 2) * sizeof(char *));
  48.     if (!argblk)
  49.     {
  50. #if OSK
  51.         _errmsg(errno, "Can't get enough memory\n");
  52. #else
  53.         perror(argv[0]);
  54. #endif
  55.         exit(2);
  56.     }
  57.  
  58.     /* find the last letter in the invocation name of this program */
  59.     i = strlen(argv[0]);
  60. #if MSDOS || TOS
  61.     /* we almost certainly must bypass ".EXE" or ".TTP" from argv[0] */
  62.     if (i > 4 && argv[0][i - 4] == '.')
  63.         i -= 4;
  64. #endif
  65.     letter = argv[0][i - 1];
  66.  
  67.     /* copy argv to argblk, possibly inserting a flag such as "-R" */
  68.     argblk[0] = ELVIS;
  69.     i = j = 1;
  70.     switch (letter)
  71.     {
  72.       case 'w':            /* "view" */
  73.       case 'W':
  74.         argblk[i++] = "-R";
  75.         break;
  76. #if !OSK
  77.       case 'x':            /* "ex" */
  78.       case 'X':
  79.         argblk[i++] = "-e";
  80.         break;
  81. #endif
  82.       case 't':            /* "input" */
  83.       case 'T':
  84.         argblk[i++] = "-i";
  85.         break;
  86.     }
  87.     while (j < argc)
  88.     {
  89.         argblk[i++] = argv[j++];
  90.     }
  91.     argblk[i] = (char *)0;
  92.  
  93.     /* execute the real ELVIS program */
  94. #if OSK
  95.     pid = os9exec(chainc, argblk[0], argblk, environ, 0, 0, 3);
  96.     fprintf(stderr, "%s: cannot execute\n", argblk[0]);
  97. #else
  98.     (void)execvp(argblk[0], argblk);
  99.     perror(ELVIS);
  100. #endif
  101. }
  102.